﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AvalonDock;

namespace HA.ModFlow.Application
{

    /// <summary>
    /// 设计用于存储所有的视图控制
    /// </summary>
   public class UIModule
    {

       protected UIModule()
       {

           this._ribbonV2ViewModel = new RibbonViewModelV2();
          
       }







       static UIModule defaultModule;

       public static UIModule DefaultModule
       {
           get {

               if (defaultModule==null)
               {
                   defaultModule = new UIModule();
                   
               }
               
               return UIModule.defaultModule; 
           
           }
           
       }




       ProjectViewModel _projectViewModel;

       public ProjectViewModel ProjectViewModel
       {
           get { return _projectViewModel; }
          
       }





        //RibbonViewModel _ribbonViewModel;

        //public RibbonViewModel RibbonViewModel
        //{
        //    get { return _ribbonViewModel; }
          
        //}


        RendererViewModel _rendererViewModel;

        public RendererViewModel RendererViewModel
        {
            get { return _rendererViewModel; }
          
        }





       //进入第二版设计阶段

        RibbonViewModelV2 _ribbonV2ViewModel;

        public RibbonViewModelV2 RibbonV2ViewModel
        {
            get { return _ribbonV2ViewModel; }
            
        }



        DockingManager _dockingManager;

        public DockingManager DockingManager
        {
            get { return _dockingManager; }
            set { _dockingManager = value; 
            

            }
        }

        DocumentContent _documentContent;

        public DocumentContent DocumentContent
        {
            get { return _documentContent; }
            set { _documentContent = value; }
        }





        RibbonView _ribbonView;

        public RibbonView RibbonView
        {
            get { return _ribbonView; }
            set { 
                
                _ribbonView = value;

                if (this._ribbonView!=null)
                {
                    this._ribbonView.ViewModel = this._ribbonV2ViewModel;
                    
                }
              
            
            }
        }

        ProjectView _projectView;

        public ProjectView ProjectView
        {
            get { return _projectView; }
            set { _projectView = value; }
        }

        RendererView _rendererView;

        public RendererView RendererView
        {
            get { return _rendererView; }
            set { _rendererView = value;


         
            
            
            }
        }



        RecentProjectViewModel _recentProject;

        public RecentProjectViewModel RecentProject
        {
            get { return _recentProject; }
            set { _recentProject = value; }
        }




        protected void ResetViewModel()
        {

            //_ribbonViewModel = new RibbonViewModel();

            _projectViewModel = new ProjectViewModel();

            _rendererViewModel = new RendererViewModel();

            if (this._ribbonView!=null)
            {
                //this._ribbonView.ViewModel = this._ribbonViewModel;

                this._ribbonV2ViewModel.OnResetProject();


            }

            if (this._projectView!=null)
            {

                this._projectView.ViewModel = this._projectViewModel;

                
            }

            if (this._rendererView!=null)
            {
                this._rendererView.ViewModel = this._rendererViewModel;

                
            }

        
          

          
 
        }

       

        




        public void DefaultService_ProjChanged(HAUtil.ProjChangedType chType)
        {

            ///刷新界面显示
            ///

            //测试基本的三维框架

            //暂时让新建和打开逻辑走一套代码，即新建逻辑


            switch (chType)
            {
                case HAUtil.ProjChangedType.NEW:

                    this.ResetViewModel();
                    

                    break;
                case HAUtil.ProjChangedType.SAVE:

                    break;
                case HAUtil.ProjChangedType.CLOSE:

                    this.ResetViewModel();

                    

                    break;
                case HAUtil.ProjChangedType.OPEN:


                    this.ResetViewModel();

                    this.RibbonV2ViewModel.ViewOpViewModel.MinGridVM.ViewMode = this.RibbonV2ViewModel.ViewOpViewModel.MinGridVM.ViewMode;

                    break;
                default:
                    break;
            }







        }




        public void ShowTimeStepView(bool b)
        {
            if (b)
            {
                this._projectView.tsvDataset.Visibility = System.Windows.Visibility.Visible;

            }
            else
            {
                this._projectView.tsvDataset.Visibility = System.Windows.Visibility.Collapsed;
 
            }
        }



    }
}
